package com.elysia.gulimall.product.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;

@Configuration
public class RedissonConfig {
    @Value("${spring.redis.host}"+":"+"${spring.redis.port}")
    private String singleAddress;
    @Bean(destroyMethod = "shutdown")
    public RedissonClient redisson() throws IOException {
        Config config = new Config();
        /*
          SingleServer() 单节点模式
          redis:// redis 连接协议
         */
        config.useSingleServer()
                .setAddress("redis://"+singleAddress);

        return Redisson.create(config);
    }
}
